import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CheckboxWidget extends StatefulWidget {
  Function? onChanged;
  bool select;

  CheckboxWidget({Key? key, this.onChanged, this.select: false})
      : super(key: key);

  @override
  State<CheckboxWidget> createState() => _CheckboxWidgetState();
}

class _CheckboxWidgetState extends State<CheckboxWidget> {
  bool select = false;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    select = widget.select;
  }

  @override
  void didUpdateWidget(covariant CheckboxWidget oldWidget) {
    // TODO: implement didUpdateWidget
    super.didUpdateWidget(oldWidget);
    select = widget.select;
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      child: Container(
        width: 15.w,
        height: 15.w,
        child: Center(
          child: Icon(
            Icons.check_outlined,
            color: select ? Color(0xFFFEBA07) : Colors.transparent,
            size: 11.w,
          ),
        ),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(50.w),
            border: Border.all(
                width: 1.w,
                color: select ? Color(0xFFFEBA07) : Color(0xFF999999))),
        margin: EdgeInsets.all(10.w),
      ),
      onTap: () {
        setState(() {
          select = !select;
          widget.onChanged!(select);
        });
      },
    );
  }
}
